<template>
    <div id="app-container" style="margin: 10px 50px">
      <el-form :inline="true" :model="student" class="demo-form-inline">
        <el-form-item label="学生姓名">
          <el-select
            filterable
            v-model="FormData.studentId"
            placeholder="学生姓名"
          >
            <el-option
              v-for="item in student.optionsStu"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="日志状态">
          <el-select v-model="FormData.status" placeholder="日志状态">
            <el-option
              v-for="item in student.optionsStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="default" @click="clear">清空</el-button>
          <!-- 导出实习日志的数据 -->
          <el-button type="default" @click="exportData">导出数据</el-button>
        </el-form-item>
      </el-form>
  
      <el-table :data="logInfo" stripe style="width: 100%">
        <el-table-column prop="studentName" label="学生姓名" width="190">
        </el-table-column>
  
        <el-table-column prop="statusString" label="日志状态" width="350">
        </el-table-column>
  
        <el-table-column prop="createTime" label="提交时间" > </el-table-column>
  
        <el-table-column label="操作" width="400" align="center">

          

          <template slot-scope="scope">

            <el-button @click="showDetail(scope.row)" size="mini" type="show"
              >实习详情</el-button
            >

            <el-button @click="show(scope.row)" size="mini" type="show"
              >阅览</el-button
            >
  
            <!-- <el-button
              v-if="scope.row.status == 1"
              size="mini"
              disabled
              type="danger"
              >已查看</el-button
            >
  
            <el-button
              v-if="scope.row.status == -1"
              size="mini"
              disabled
              type="danger"
              >已打回</el-button
            >
  
            <el-button
              v-if="scope.row.status == 0"
              size="mini"
              @click="changeStatus(scope.row)"
              type="primary"
              >确认查看</el-button
            >
  
            <el-button
              v-if="scope.row.status == 0"
              size="mini"
              @click="refuse(scope.row)"
              type="danger"
              >打回重改</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>
  
      <el-dialog
        title="退回原因："
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose"
      >
        <el-input
          type="textarea"
          placeholder="请输入内容"
          v-model="comment"
          maxlength="300"
          show-word-limit
        >
        </el-input>
  
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="refuseInfo">确 定</el-button>
        </span>
      </el-dialog>
  
      <div class="block">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page.sync="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </template>
  
  <script>
  import teacherApi from "@/api/teacher";
  import studentApi from "@/api/student";
  import logApi from "@/api/log";
  
  export default {
    data() {
      return {
        row: {},
        dialogVisible: false,
        curPage: 1,
        pageSize: 10,
        total: 0,
  
        student: {
          optionsStu: [],
          optionsStatus: [
            {
              label: "已阅览",
              value: "1"
            },
            {
              label: "未阅览",
              value: "0"
            }
          ]
        },
        FormData: {
          studentId: "",
          status: "",
          teacherId: ""
        },
        logInfo: [],
        comment: "",
        teacherId: ""
      };
    },
    created() {
      // 查询所有的日志记录（当前教师下面所有学生的日志）
      logApi.pageAllList(this.curPage, this.pageSize, this.FormData).then(resp => {
        this.logInfo = resp.data.list;
        this.total = resp.data.total;
      });
    },
    mounted() {
      this.init();
    },
    methods: {
      exportData(){
        window.open("http://localhost:8222/admin/log/grade/export");
        alert("数据已导出！数据量有点大，请耐心等待！")

      },
      refuseInfo() {
        logApi.changeStatus(this.row.studentId, -1, this.comment).then(resp => {
          this.$message({
            type: "success",
            message: "打回成功!"
          });
        });
       
        // 查询所有的日志记录（当前教师下面所有学生的日志）
        logApi.pageAllList(this.curPage, this.pageSize, this.FormData).then(resp => {
          this.logInfo = resp.data.list;
          this.total = resp.data.total;
        });
        this.dialogVisible = false;
      },
      refuse(row) {
        console.log(row, "数据");
        this.row = row;
        this.dialogVisible = true;
      },
      handleClose(done) {
        this.$confirm("确认关闭？")
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      show(row) {
        console.log(row);
        window.open(row.fileUrl);
      },
      showDetail(row){
        console.log(row,"showDetail")
        this.$router.push('/log/show/' + row.studentId);
      },
      init() {
        // 搜索栏学生信息填充
        studentApi.getPackageStudentInfo().then(resp => {
          this.student.optionsStu = resp.data.list;
        });
      },
      onSubmit() {
        logApi.pageAllList(this.curPage, this.pageSize, this.FormData).then(resp => {
          this.logInfo = resp.data.list;
          this.total = resp.data.total;
        });
      },
      clear() {
        this.FormData = {};
        this.FormData.teacherId = this.teacherId;
        this.onSubmit();
      },
      changeStatus(row) {
        this.$confirm("此操作将确认查阅, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            logApi.changeStatus(row.studentId, 1).then(resp => {
              this.$message({
                type: "success",
                message: "状态修改成功!"
              });
            });
            logApi
              .pageAllList(this.curPage, this.pageSize, this.FormData)
              .then(resp => {
                this.logInfo = resp.data.list;
                this.total = resp.data.total;
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消查阅"
            });
          });
      },
      // 页数发生变化
      handleCurrentChange() {
        logApi.pageAllList(this.curPage, this.pageSize, this.FormData).then(resp => {
          this.logInfo = resp.data.list;
          this.total = resp.data.total;
        });
      }
    }
  };
  </script>
  
  <style></style>
  